<template>
  <transition name="move">
    <div class="perfect-form">
      <form-wrap bg="background: #fff" :title="title">
        <div slot="form">
          <i-Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
            <FormItem label="Name" prop="name">
              <i-input class="input-item" v-model="formValidate.name" placeholder="Enter your name"></i-input class="input-item">
            </FormItem>
            <FormItem label="City" prop="city" class="input-item">
              <Select v-model="formValidate.city" placeholder="Select your city">
                <Option value="beijing">New York</Option>
                <Option value="shanghai">London</Option>
                <Option value="shenzhen">Sydney</Option>
              </Select>
            </FormItem>
            <FormItem label="Date" class="input-item">
              <Row>
                <Col span="11">
                <FormItem prop="date">
                  <DatePicker type="date" placeholder="Select date" v-model="formValidate.date"></DatePicker>
                </FormItem>
                </Col>
                <Col span="2" style="text-align: center">-</Col>
                <Col span="11">
                <FormItem prop="time">
                  <TimePicker type="time" placeholder="Select time" v-model="formValidate.time"></TimePicker>
                </FormItem>
                </Col>
              </Row>
            </FormItem>
            <FormItem label="Gender" prop="gender">
              <RadioGroup v-model="formValidate.gender">
                <Radio label="male">Male</Radio>
                <Radio label="female">Female</Radio>
              </RadioGroup>
            </FormItem>
            <FormItem label="Hobby" prop="interest">
              <CheckboxGroup v-model="formValidate.interest">
                <Checkbox label="Eat"></Checkbox>
                <Checkbox label="Sleep"></Checkbox>
                <Checkbox label="Run"></Checkbox>
                <Checkbox label="Movie"></Checkbox>
              </CheckboxGroup>
            </FormItem>
            <FormItem label="Desc" prop="desc">
              <i-input class="input-item" v-model="formValidate.desc" type="textarea" :autosize="{minRows: 2,maxRows: 5}" placeholder="Enter something..."></i-input class="input-item">
            </FormItem>
            <FormItem>
              <Button type="primary" @click="handleSubmit('formValidate')">Submit</Button>
              <Button type="ghost" @click="handleReset('formValidate')" style="margin-left: 8px">Reset</Button>
            </FormItem>
          </i-Form>
        </div>
      </form-wrap>
    </div>
  </transition>
</template>

<script type="text/ecmascript-6">
  import FormWrap from 'base/form-wrap/form-wrap'

  export default {
    data () {
      return {
        title: '完善个人信息',
        formValidate: {
          name: '',
          city: '',
          gender: '',
          interest: [],
          date: '',
          time: '',
          desc: ''
        },
        ruleValidate: {
          name: [
            { required: true, message: '请填写用户名称', trigger: 'blur' }
          ],
          city: [
            { required: true, message: '请选择城市', trigger: 'change' }
          ],
          gender: [
            { required: true, message: '请选择性别', trigger: 'change' }
          ],
          interest: [
            { required: true, type: 'array', min: 1, message: '请选择你的爱好', trigger: 'change' },
            { type: 'array', max: 2, message: '请不要超过2个好吗^_^', trigger: 'change' }
          ],
          date: [
            { required: true, type: 'date', message: '请选择日期', trigger: 'change' }
          ],
          time: [
            { required: true, type: 'string', message: '请选择时间', trigger: 'change' }
          ],
          desc: [
            { required: true, message: '请填入个人简介！', trigger: 'blur' },
            { type: 'string', min: 20, message: '请保持在20个单词量！', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      handleSubmit (name) {
        this.$refs[name].validate((valid) => {
          if (valid) {
            this.$Message.success('Success!');
          } else {
            this.$Message.error('Fail!');
          }
        })
      },
      handleReset (name) {
        this.$refs[name].resetFields();
      }
    },
    components: {
      FormWrap
    }
  }
</script>

<style scoped lang="stylus" rel="stylesheet/stylus">
  @import "~@/common/stylus/variable.styl"
  @import "~@/common/stylus/mixin.styl"

  .perfect-form
    ltposition(0, 0)
    wh(100%, 100%)
    color: $vice-color
    background-color: rgba(0, 0, 0, .8)
    .ivu-form
      .ivu-form-item
        label
          color: $white
    .input-item
      padding-right: 20px



  move-enter-active, .move-leave-active
    transiti(transform, .5s, ease)
  .move-enter
    -webkit-transform: translate3d(-100%, 0, 0)
    -moz-transform: translate3d(-100%, 0, 0)
    -ms-transform: translate3d(-100%, 0, 0)
    -o-transform: translate3d(-100%, 0, 0)
    transform: translate3d(-100%, 0, 0)
  .move-leave
    -webkit-transform: translate3d(100%, 0, 0)
    -moz-transform: translate3d(100%, 0, 0)
    -ms-transform: translate3d(100%, 0, 0)
    -o-transform: translate3d(100%, 0, 0)
    transform: translate3d(100%, 0, 0)
</style>